<template>
    <div style="min-width:829px">
        <!-- 汇款列表 -->
        <div v-if="$route.path == '/incomeStatement'">
            <div class="vs-search-box">
                <el-form ref="form" v-search-box-enter :inline="true" :model="paging" label-width="110px">
                    <el-form-item label="查询时间段：">
                        <el-date-picker v-model="bill_time_start" type="daterange" format="yyyy-MM-dd"
                            value-format="yyyy-MM-dd" start-placeholder="开始时间" end-placeholder="结束时间"
                            style="width:300px">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item class="vs-right-btns">
                        <el-button @click="reset">重置</el-button>
                        <el-button @click="handleCurrentChange(1)" type="primary">查询</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <div class="vs-table-box">
                <!-- <div class="operation-box clear-float">
                    <el-button type="primary" @click="dialogVisible = true">新增打款</el-button>
                    <el-button >导出</el-button>
                </div> -->
                <el-table v-loading="loading" :data="tableData" header-row-class-name="has-gutter-table"
                    style="width: 100%" border show-summary :summary-method="getSummaries">
                    <el-table-column type="index" label="序号" align="center" width="50"></el-table-column>
                    <el-table-column prop="date" label="日期" align="center"></el-table-column>
                    <el-table-column prop="project" label="服务项目总额" align="center"></el-table-column>
                    <el-table-column prop="takeTicket_one" label="成品销售总额" align="center"></el-table-column>
                    <el-table-column prop="takeTicket_two" label="毛坯销售总额" align="center"></el-table-column>
                    <el-table-column prop="goods" label="洗护产品销售总额" align="center"></el-table-column>
                    <el-table-column prop="prices" label="充值总额" align="center"></el-table-column>
                    <el-table-column prop="total" label="当日合计" align="center"></el-table-column>
                </el-table>
            </div>
        </div>
        <router-view></router-view>
    </div>
</template>

<script>
export default {
    data() {
        return {
            loading: false,
            bill_time_start: [],
            paging: {
                page: 1,
                total: 0,
                limit: 10,
            },
            tableData: [],
        };
    },
    created() {
        if (this.$route.path == '/incomeStatement') {
            this.handleCurrentChange(1);
        }
    },
    methods: {
        getSummaries(param) {
            const { columns, data } = param;
            const sums = [];
            columns.forEach((column, index) => {
                if (index == 0) {
                    sums[index] = '合计';
                    return;
                }
                const values = data.map(item => Number(item[column.property]))
                if (column.property == 'project' || column.property == 'takeTicket_one' || column.property == 'takeTicket_two' || column.property == 'goods' || column.property == 'prices' || column.property == 'total') {
                    sums[index] = values.reduce((prev, curr) => {
                        const value = Number(curr);
                        if (!isNaN(value)) {
                            return prev + curr;
                        } else {
                            return prev;
                        }
                    }, 0);
                    sums[index] = sums[index].toFixed(2)
                } else {
                    sums[index] = '';
                }
            });
            return sums;
        },
        async repairGetList() {
            if (!this.bill_time_start) {
                this.bill_time_start = []
            }
            this.paging.date_start = this.bill_time_start[0] || ''
            this.paging.date_end = this.bill_time_start[1] || ''
            let obj = Object.assign({}, this.paging);
            this.loading = true;
            let { code, data } = await this.$Http.getIncome(obj);
            this.loading = false;
            if (code) {
                this.tableData = data;
                // this.paging.total = data.total;
            }
        },
        reset() {//重置
            this.paging = this.$options.data().paging;
            this.handleCurrentChange(1)
        },
        handleSizeChange(val) {
            this.paging.limit = val;
            this.repairGetList()
        },
        handleCurrentChange(val) {
            this.paging.page = val;
            this.repairGetList()
        }
    },
};
</script>

<style lang="scss" scoped>
::v-deep {
    .el-dialog__header {
        border-bottom: 1px solid rgba($color: #000000, $alpha: 0.1);
    }
}

.image-thumbnail {
    width: 130px;
    height: 130px;
}

.divTableHead {
    width: 100%;

    div {
        border-top: 1px solid #ebeef5;
        border-left: 1px solid #ebeef5;
        border-right: 1px solid #ebeef5;
        height: 50px;
        line-height: 50px;
        text-align: center;
    }
}

.divTable {
    width: 100%;

    div {
        border-bottom: 1px solid #ebeef5;
        border-left: 1px solid #ebeef5;
        border-right: 1px solid #ebeef5;
        height: 50px;
        line-height: 50px;
        padding-left: 30px;
    }
}

table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    table-layout: fixed;

    td {
        border: 1px solid #ebeef5;
        text-align: center;
        height: 32px;
        color: #333333;
        padding: 0 5px;
        font-size: 14px;
    }
}
</style>